const fs = require('fs');

var rds = fs.createReadStream('input.txt');
var cnt = 0;

//var globalData = new Buffer('');

rds.on('data',function(trunk){
    cnt++;
    console.log('第'+ cnt+'次读取，共'+Buffer.byteLength(trunk)+'字节。'); 
    globolData += trunk;
    //console.log(trunk);

});

rds.on('end',function(){
    console.log("读取文件已完成!");
});

rds.on('close',function(){
    console.log("文件已关闭!");
});

rds.on('open',function(){
    console.log("文件已打开!");
    console.log(globolData);
});

rds.on('error',function(err){
    console.log(err);
});

console.log("程序执行完毕！");